package com.hmdp.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;

import lombok.Data;
import org.springframework.data.redis.core.ZSetOperations;

/**
 * @author Administrator
 * @TableName tb_blog_like
 */
@TableName(value = "tb_blog_like")
@Data
public class BlogLike implements Serializable, ZSetOperations.TypedTuple<String> {
    /**
     *
     */
    @TableField(value = "blog_id")
    private Integer blogId;

    /**
     *
     */
    @TableField(value = "user_id")
    private Integer userId;
    /**
     * 博客点赞数
     */
    @TableField(exist = false)
    private Double score;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object target) {
        if (target instanceof BlogLike) {
            return ((BlogLike) target).getBlogId().equals(blogId) && ((BlogLike) target).getUserId().equals(userId);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int result = 17;
        if (blogId != null) {
            result = result * 31 + blogId.hashCode();
        }
        if (userId != null) {
            result = result * 31 + userId.hashCode();
        }
        if (score != null) {
            result = result * 31 + score.hashCode();
        }
        return result;
    }

    @Override
    public String getValue() {
        return getBlogId().toString();
    }

    @Override
    public Double getScore() {
        return score;
    }

    public int compareTo(Double o) {

        double thisScore = (score == null ? 0.0 : score);
        double otherScore = (o == null ? 0.0 : o);

        return Double.compare(thisScore, otherScore);
    }

    @Override
    public int compareTo(ZSetOperations.TypedTuple<String> o) {

        if (o == null) {
            return compareTo(Double.valueOf(0));
        }

        return compareTo(o.getScore());

    }
}